from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
import time
import unittest


class wangyiyunyued(unittest.TestCase):

    def setUp(self) -> None:
        # 打开浏览器
        self.driver = webdriver.Chrome()
        self.driver.get('https://yuedu.163.com/')
        time.sleep(2)
        # 窗口最大化
        self.driver.maximize_window()
        self.driver.implicitly_wait(5)

    def tearDown(self) -> None:
        time.sleep(5)
        self.driver.quit()

    def test_wangyiyunyued_01(self):
        # 悬停在登录上
        xt = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[1]/div[1]/div/div[2]/div/a[1]')
        ActionChains(self.driver).move_to_element(xt).perform()
        time.sleep(2)
        # 点击手机号密码登录
        self.driver.find_element(By.PARTIAL_LINK_TEXT, '手机号登录').click()
        time.sleep(2)
        # 输入手机号
        self.driver.find_element(By.NAME, 'cellPhone').send_keys('15985645480')
        time.sleep(2)
        # 输入密码
        self.driver.find_element(By.NAME, 'password').send_keys('gW09092434')
        time.sleep(2)
        # 点击登录按钮
        self.driver.find_element(By.CLASS_NAME, 'row.row-2').click()
        time.sleep(2)
        # 断言1：验证登录成功后断言：小高大王
        dy1 = self.driver.find_element(By.XPATH, '/html/body/div[1]/div[1]/div[1]/div[1]/div/div[2]/div/a[1]/span').text
        self.assertEqual('小高大王', dy1)


if __name__ == '__main__':
    unittest.main()
